package com.wyw.design.model.learning.behavioral.iteratorpattern;

import java.util.Vector;

/**
 * @Title   具体聚集
 * @Description
 * @Author Mr Wu yewen.wu.china@gmail.com
 * @Date 2023/4/18 10:07
 * Update History:
 * Author        Time            Content
 */
public class ConcreteAggregate implements Aggregate {
    // 私有存储容器
    private Vector vector = new Vector();
    // 添加元素
    @Override
    public void add(Object obj) {
        this.vector.add(obj);
    }
    // 根据下标获取元素
    public Object getElement(int index) {
        return vector.get(index);
    }
    // 获取集合长度
    public int size() {
        return vector.size();
    }
    // 创建迭代器
    @Override
    public Iterator createIterator() {
        return new ConcreteIterator(this);
    }
}